﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SLHtmlExtractor.ObjectOutput;
using HtmlExtractor;
using Reader.Domain;

namespace SlTest
{
    public class DataTypeConverter
    {
        
    }
    [TestClass]
    public class ObjectOutputTest:TestBase
    {

        public ObjectOutputTest()
        {
            ExtractorFile = @"Resource/ObjectExtractor.config";
        }
        [TestMethod]
        public void SimpleTest()
        {
            string parseUri = @"http://www.lxwxw.com/xiaoshuoinfo/69/69255.html";
            string textUri = @"\Resource\lxwxw\bookpage.txt";
            ExtractorFile = @"Resource/ObjectExtractor.config";
            PageResult result = GetLoacalPageResult(parseUri, textUri);    
          
            object b=new BookPage();
            ConvertToObject ct = new ConvertToObject();
            ct.TryGetOutPutResult(result, ref b);
            BookPage bp = (BookPage)b;
            Assert.AreEqual("《邪龙道》",bp.BookName);
            Assert.AreEqual("武侠修真",bp.Catalog);
            Assert.AreEqual("血红", bp.Author);
            Assert.AreEqual(DateTime.Parse("2010-05-24"),bp.LastUpdateTime);
            Assert.AreEqual(@"他绝对不是一个好人；他绝对不是一个坏人；他的人生信仰是和气生财；一个个上古仙神以一个迥异的方式出现在他身边；一个个奇异、奇怪的人自愿或者不自愿的在他身边聚集；最终，他一飞冲天；",bp.Introduce);
            Assert.AreEqual("http://www.lxwxw.com/files/article/html/69/69255/index.html",bp.BookContentUri);
            Assert.AreEqual("http://www.lxwxw.com/files/article/image/69/69255/69255s.jpg",bp.ImageUri);
            Assert.AreEqual(@"http://www.lxwxw.com/files/article/html/69/69255/12977887.html",bp.NewChapter.Uri);
            Assert.AreEqual("第一百五十八章 星级走私商（上）",bp.NewChapter.Name);
            
        }
        [TestMethod]
        public void CompositeTest()
        {//集合
            string parseUri = @"http://www.lxwxw.com/files/article/html/69/69255/index.html";
            string textUri = @"\Resource\lxwxw\content.txt";
            PageResult result = GetLoacalPageResult(parseUri, textUri);
            object b = new BookContent();
            ConvertToObject ct = new ConvertToObject();
            ct.TryGetOutPutResult(result, ref b);
            BookContent bp = (BookContent)b;
            Assert.AreEqual(@"第七章 伏击", bp.Chapters[7].Name);
            Assert.AreEqual(@"http://www.lxwxw.com/files/article/html/69/69255/12686858.html", bp.Chapters[7].Uri);
            Assert.AreEqual(337, bp.Chapters.Count);
            Assert.AreEqual("邪龙道", bp.BookName);
            Assert.AreEqual("作者：血红", bp.Author);
            //
        }
         /// <summary>
         /// 
         /// </summary>
        public void ListStringTest()
        {
    //        <PageRule name="章节">
    //    <TargetUri><![CDATA[^http://(?<domain>www\.lxwxw\.com)/files/article/html/\d+/\d+/\d+\.html$]]></TargetUri>
    //    <Group>
    //        <Regex><![CDATA[chaptername='(.*?)']]></Regex>
    //        <GroupInfo outputPath="Title"/>
    //    </Group>
    //    <Group>
    //        <Regex><![CDATA[next_page\s*=\s*"(.*?)"]]></Regex>
    //        <GroupInfo outputPath="NextUri"/>
    //    </Group>
    //    <Group>
    //        <Regex><![CDATA[preview_page\s*=\s*"(.*?)"]]></Regex>
    //        <GroupInfo outputPath="PreviousUri"/>
    //    </Group>
    //    <Group>
    //        <Regex><![CDATA[index_page\s*=\s*"(.*?)"]]></Regex>
    //        <GroupInfo outputPath="BookPageUri"/>
    //    </Group>
    //    <Group>
    //        <Regex><![CDATA[<img src="(.*?)" border="0" class="imagecontent">]]></Regex>
    //        <GroupInfo outputPath="ImageContent.String"/>
    //    </Group>
    //    <Group>
    //        <Regex><![CDATA[(?i:<div\s*id=content.*>(?s:(.*?))</div>)]]></Regex>
    //        <GroupInfo outputPath="TextContent">
    //            <ReplaceExpression>
    //                <FindRegex><![CDATA[(?:<br />){0,}(?:&nbsp;){1,}]]></FindRegex>
    //                <DirectReplace><![CDATA[<p>]]></DirectReplace>
    //            </ReplaceExpression>
    //            <ReplaceExpression>
    //                <FindRegex>\s+</FindRegex>
    //                <DirectReplace/>
    //            </ReplaceExpression>
    //        </GroupInfo>
    //    </Group>
    //</PageRule>
            //textChapter.txt 文本
            //ParserContext context = new ParserContext(, Uri);
            //string extractorFile = @"Resource/ObjectExtractor.config";
            //Extractor extr = new Extractor(extractorFile);
            //PageResult result;
            //extr.TryGetResult(context, out result);

            //object b = new BookChapter();
            //ConvertToObject ct = new ConvertToObject();
            //ct.TryGetOutPutResult(result, ref b);
            //BookChapter bp = (BookChapter)b;
         
            // DownloadPage(bp.ImageUri);

        }
    }
}
